{{--
/**
 * Created by PhpStrom
 * User: 郭碧云
 * Date: 2021/3/9 15:07
 * Desc:
 */--}}
<form id="permission_edit" style="margin-top: 15px;" class="layui-form" @if($error>0) @else action="{{route('system.permission.update',['id'=>$permission->id])}}" @endif>
    {{csrf_field()}}
    <div class="layui-form-item">
        <label class="layui-form-label">权限分组</label>
        <div class="layui-input-block">
            <select id="type" name="data[type]">
                {!! Code::getOptionsByCode('PERMISSION_GROUP',$permission->type) !!}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">父权限</label>
        <div class="layui-input-block">
            <div id="parent_id" style="width: 60%"></div>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" id="name" name="data[name]" @if($error>0) @else value="{{$permission->name}}" @endif autocomplete="off" placeholder="请输入权限名称" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">守卫</label>
        <div class="layui-input-block">
            <select id="type" name="data[guard_name]" disabled lay-verify="required">
                {!! Code::getOptionsByCode('GUARD','',$permission->guard_name) !!}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">显示名称</label>
        <div class="layui-input-block">
            <input type="text" id="display_name" name="data[display_name]" @if($error>0) @else value="{{$permission->display_name}}" @endif autocomplete="off" placeholder="请输入权限显示名称" class="layui-input">
        </div>
    </div>

</form>

<script>
    $(function (){
        $("#name").blur(function (){
            admin.send('{{route('system.permission.check')}}','GET',{'data':{'name':$("#name").val(),'type':$("#type").val()}},0);
        });
    })
</script>

<script src="{{asset('layui/modules/xm-select.js')}}"></script>
<script src="{{asset('js/tree/select.js')}}"></script>
<script>
    var idx = -1;
    layui.use(['xmSelect'], function () {
        var xmSelect = layui.xmSelect;
        let params=selectTreeParams('#parent_id','data[parent_id]','请选择',"{{$permission->parent_id}}",JSON.parse('{!! $permissions !!}'),function (data){
        });
        xmSelect.render(params)
    });
</script>

